<template>
    <div>
    <el-form
      label-position="left"
      label-width="80px"
      :model="goodsINFO"
      ref="goodsINFO"
      style="margin-top:100px;margin-left:100px;"
    >
      <el-form-item label="商品名称" prop="name">
        <el-input v-model="goodsINFO.name" style="width:300px;"></el-input>
      </el-form-item>
      <el-form-item label="商品价格" prop="price">
        <el-input v-model="goodsINFO.price" style="width:300px;"></el-input>
      </el-form-item>
      <el-form-item label="商品库存" prop="nums">
        <el-input v-model="goodsINFO.nums" style="width:300px;"></el-input>
      </el-form-item>
      <el-form-item label="商品类型" prop="type">
        <el-input v-model="goodsINFO.type" style="width:300px;"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm">立即修改</el-button>
        <el-button @click="resetForm('goodsINFO')">重置</el-button>
      </el-form-item>
    </el-form>
    <el-link type="primary" @click="getBackInfo">点击返回</el-link>
    </div>
</template>
<script>
export default {
    data(){
        return{
            goodsINFO:{
                name:this.$store.state.goods_name,
                price:this.$store.state.goods_price,
                nums:this.$store.state.goods_num,
                type:this.$store.state.goods_type
            }
        }
    },
    methods:{
        submitForm(){
            if(this.goodsINFO.name==""||this.goodsINFO.price==""||this.goodsINFO.nums==""||this.goodsINFO.type==""){
                alert("请填写完整的信息");
            }else{
                let goodsinfo = {
                    'goodsid':this.$route.params.id,
                    'goodsname':this.goodsINFO.name,
                    'goodsprice':this.goodsINFO.price,
                    'goodsnum':this.goodsINFO.nums,
                    'goodstype':this.goodsINFO.type
                };
                this.axios.post("/api/shopping/editGoods.php",goodsinfo).then(res=>{
                    if(res.data=="ok"){
                        alert("修改成功");
                    }else if(res.data=="error"){
                        alert("修改失败，请稍后重试");
                    }else{
                        alert("服务器繁忙,请稍后重试");
                    }
                });
            }
        },
        getBackInfo(){
            this.$router.push('/personinfo');
        },
        resetForm(formname){
            this.$refs[formname].resetFields();
        }
    }
}
</script>